package com.csp.mingyue.oss.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csp.mingyue.common.oss.constant.OssConstant;
import com.csp.mingyue.common.redis.utils.RedisUtils;
import com.csp.mingyue.oss.api.entity.SysOssConfig;
import com.csp.mingyue.oss.mapper.SysOssConfigMapper;
import com.csp.mingyue.oss.service.SysOssConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * OSS对象存储动态配置表 服务实现类
 * </p>
 *
 * @author Strive
 * @since 2023-09-11 05:55:08
 */
@Service
public class SysOssConfigServiceImpl extends ServiceImpl<SysOssConfigMapper, SysOssConfig>
		implements SysOssConfigService {

	@Override
	public void init() {
		List<SysOssConfig> list = this.list();
		// 加载 OSS 初始化配置
		for (SysOssConfig config : list) {
			String configKey = config.getConfigKey();
			if ("0".equals(config.getStatus())) {
				RedisUtils.setCacheObject(OssConstant.DEFAULT_CONFIG_KEY, configKey);
			}

			RedisUtils.setCacheMapValue(OssConstant.SYS_OSS_CONFIG, config.getConfigKey(), JSONUtil.toJsonStr(config));
		}
	}

}
